package com.SweetWhite.UserManagement.model.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.SweetWhite.UserManagement.model.service.DeleteService;
import com.SweetWhite.UserManagement.model.service.SelectService;



@Controller
public class DeleteController extends HttpServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
@Autowired
private DeleteService service;
@Autowired
private SelectService s_service;
	@RequestMapping("delete.action")
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
	req.setCharacterEncoding("UTF-8");
	resp.setCharacterEncoding("UTF-8");
	PrintWriter pw=resp.getWriter();
	int No=Integer.parseInt(req.getParameter("No"));
	if(No==0) {
		pw.print("哎呀，管理员的号可删不得");
	}else
	try {
		if((s_service.getHero_UserByNo(No).getNo()+"").isEmpty()==false) {
			service.deleteHero_User(No);
			pw.print("删除成功");
		}
	} catch (Exception e) {
		// TODO: handle exception
		service.deleteHero_User(No);
		pw.print("删无可删");
	}finally {
		pw.flush();
		pw.close();	
	}
	}
}
